<?php
/**
 */
class NotificationsTable extends Doctrine_Table
{
	public function getNotifications($user_id)
	{
		$query = new Doctrine_Query();
		$query->select('n.*')
		       ->from('Notifications n')
			   ->where("n.user_id='".$user_id."'");
			   
		$result = $query->execute(array(),Doctrine::HYDRATE_ARRAY);
		return $result;
	        
	}
	public function getNotificationss($user_id)
	{
		$query = new Doctrine_Query();
		$query->select('n.*')
		       ->from('Notifications n')
			   ->where("n.user_id='".$user_id."'");
			   
		$result = $query->execute(array(),Doctrine::HYDRATE_ARRAY);
		return $result[0];
	        
	}
	public function getUserId($user_id)
	{
		$query = new Doctrine_Query();
		$query->select('count(n.id) as numCount')
		       ->from('Notifications n')
			   ->where("n.user_id='".$user_id."'");
			   
		$result = $query->execute(array(),Doctrine::HYDRATE_ARRAY);
		return $result[0];
	        
	}
	public function addNotifications($user_id,$data)
	{
		$Notifications = new Notifications();
		$Notifications ->user_id = $user_id;
		$Notifications ->mytrigger_comments = $data['checkbox1'];
		$Notifications ->others_shared_triggers = $data['checkbox2'];
		$Notifications ->comments_others_shared = $data['checkbox3'];;
		$Notifications ->confirm_friend_request = $data['checkbox4'];
		$Notifications ->add_friend = $data['checkbox5'];
		$Notifications ->addto_group = $data['checkbox6'];
		
        //echo '<pre>';print_r($Expressions);exit;
		$Notifications ->save();
		return $Notifications->id;
	}
	public function updateNotifications($user_id,$data)
	{
		$i =1;
		while($i<=6)
		{
			if(isset($data['checkbox'.$i]))
			{
				$data['checkbox'.$i] = 'on';
			} else {
				$data['checkbox'.$i] = 'off';
			}
			$i++;
		}
		//echo '<pre>';print_r($data);exit;
		 $query = new Doctrine_Query();
		$query->update('Notifications n')
			  ->set('n.mytrigger_comments',"'".$data['checkbox1']."'")
			  ->set('n.others_shared_triggers',"'".$data['checkbox2']."'")
			  ->set('n.comments_others_shared',"'".$data['checkbox3']."'")
			  ->set('n.confirm_friend_request',"'".$data['checkbox4']."'")
			  ->set('n.add_friend',"'".$data['checkbox5']."'")
			  ->set('n.addto_group',"'".$data['checkbox6']."'")
			  ->where("n.user_id='".$user_id."'");
		  //echo $query;exit;
		return $query->execute();
	}
}